<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>后台管理模板</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="../../css/global.css" media="all">
		<link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css">
		<link rel="stylesheet" href="../../datatables/media/css/jquery.dataTables.css">
		<link rel="stylesheet" href="../../datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css">
		<style type="text/css">
			.expressdetail {
				width: 360px;
				height: 180px;
				background-color: rgba(54, 179, 168, 0.91);
				margin: 20px auto;
				text-align: center;
				box-shadow:3px 2px 6px #000
			}
			.expressdetail label {
				font-size: 17px;
				line-height: 25px;
			}
			.numItem {
				color: white;
			}
			#expressDetailselect {
				position: relative;
    			bottom: -19px;
			}
		</style>
	</head>
	<body>
		<div class="layui-layout layui-layout-admin" style="border-bottom: solid 5px #1aa094;">
			<!--头部导航-->
			<div class="layui-header header header-demo" ></div>
			<!--左侧导航-->
			<div class="layui-side layui-bg-black" id="admin-side">
			</div>
			<!--右侧具体内容-->
			<div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;padding:20px" id="admin-body">
				<div class="title">快递员账号详情</div>
				<hr/>
				<div class="expressdetail">
					<img class="detailimg" src="../../images/1.jpg" id="ehead">
					<div><label id="enickname">快递员1号</label>&nbsp;&nbsp;<label id="esex">男</label></div>
					<div><label id="courierId">13819151219</label></div>
					<div>
						<label>总接单：<label class="numItem" id="sumOrder">22</label></label>&nbsp;&nbsp;|&nbsp;&nbsp;
						<label>日均：<label class="numItem" id="dayOrder">25</label></label>&nbsp;&nbsp;|&nbsp;&nbsp;
						<label>评分：<label class="numItem" id="escore">26</label></label>
					</div>
					<div><label>创建时间：<label id="ecreateTime">2017-1-1</label></label></div>
				</div>
				<div style="float: left;position: absolute;top:272px;z-index: 99;">
					<select name="expreselect" lay-verify="" id="expressDetailselect">
						<option value="">排序方式</option>
						<option value="3">已完成订单</option>
						<option value="4">未完成订单</option>
						<option value="1">按完成使用↑</option>
						<option value="2">按完成使用↓</option>
						<option value="5">按创建时间↑</option>
						<option value="6">按创建时间↓</option>
					</select>
				</div>
				<div class="layui-form">
					<table class="layui-table" id="expressdetailTable">
						<thead>
							<tr>
								<th style="width:200px">创建日期</th>
								<th style="width:200px">完成日期</th>
								<th>寄件方</th>
								<th>收件方</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td>2017-6-30</td>
								<td>2017-6-30</td>
								<td><img src="../../images/0.jpg"><span>lzy</span></td>
								<td><img src="../../images/am.jpg"><span>beibei</span></td>
								<td>已完成</td>
								<td><div class="layui-btn  layui-btn-small">详情</div><div class="layui-btn layui-btn-danger  layui-btn-small orderclose">关闭</div></td>
							</tr>
							<tr>
								<td>2017-8-8</td>
								<td>2017-9-8</td>
								<td><img src="../../images/1.jpg"><span>czl</span></td>
								<td><img src="../../images/fems.jpg"><span>lala</span></td>
								<td>已完成</td>
								<td><div class="layui-btn  layui-btn-small">详情</div><div class="layui-btn layui-btn-danger  layui-btn-small orderclose">关闭</div></td>
							</tr>
							<tr>
								<td>2017-8-8</td>
								<td>2017-8-8</td>
								<td><img src="../../images/xiaosong.jpg"><span>hwjs</span></td>
								<td><img src="../../images/find_1.png"><span>bubu</span></td>
								<td>已完成</td>

								<td><div class="layui-btn  layui-btn-small">详情</div><div class="layui-btn layui-btn-danger  layui-btn-small orderclose">关闭</div></td>
							</tr>
						</tbody>
					</table>
				</div>
				<!--底部导航-->
				<div class="layui-footer footer footer-demo" id="admin-footer"></div>
				<!--JS模块-->
				<script type="text/javascript" src="../../layui/layui.js"></script>
				<script src="../../js/jquery-1.12.3.min.js"></script>
				<script src="../../js/index.js"></script>
				<!-- DataTables JavaScript -->
				<script src="../../datatables/media/js/jquery.dataTables.min.js"></script>
				<script>

				var data = {
					"code": 200,
					"courier": {
						"headPortraitUrl": "../../images/find_1.png",
						"nickname": "魔女宅急送",
						"sex": "女",
						"courierId": "15987776699",
						"sumOrder": 70,
						"dayOrder": 5,
						"score": 99627,
						"createTime": "1499912491339",
						// "birthday": "ccYszyCLXE",
						// "region": "RQci3K0vSS",
						// "signature": "Yk5fHdJrUw",
						// "permissions": "nPY2o2bY80",
						// "userId": "67192",
						// "money": "mMMEWKTN9V",
						// "userCourierState": 38829,
						// "idCardDown": "mV0gvEw4HN",
						// "idCardUp": "icMHXcPgCT",
						// "idCardNo": "BquhFYsDn1",
						// "readName": "AgEilzdvls",
						// "username": "ltN6ACwuYy",
						// "lastLoginTime": "1499911986636"
					}
				}

				var data2 = {
					"code": 5802,
					"orderStatisticalVos": [{
							"orderId": 12345,
							"demandCreatetime": "2017-8-8 11:30",
							"arriveTime": 4565446, //datetime
							"headPortraitUrl": "../../images/am.jpg", //收
							"nickname": "duola", //注意啦 收件方
							"purchaseUserheadPortraitUrl": "../../images/dx.jpg",
							"purchaseUserNickname": "zylin", //寄件 
							"orderState": 1, //状态
						}, {
							"orderId": 123980,
							"demandCreatetime": "2017-8-8 11:31",
							"arriveTime": 123456,
							"headPortraitUrl": "../../images/fems.jpg", //收
							"nickname": "hwj", //注意啦 收件方
							"purchaseUserheadPortraitUrl": "../../images/jn.jpg",
							"purchaseUserNickname": "linzy", //寄件 
							"orderState": 1, //状态
						}, {
							"orderId": 123666,
							"demandCreatetime": "2017-8-8 11:33",
							"arriveTime": 456123,
							"headPortraitUrl": "../../images/mm.jpg", //收
							"nickname": "mmm", //注意啦 收件方
							"purchaseUserheadPortraitUrl": "../../images/find_1.png",
							"purchaseUserNickname": "czl", //寄件 

							"orderState": 7, //状态
						},

					]
				}
				$(function() {
					$("#user").addClass('layui-this'); //对应订单管理的背景色
					$('#expressdetailTable').DataTable({
						responsive: true,
						ordering: false,
						searching: true,
						"bLengthChange": false,
						"bRetrieve": true,
						"bFilter": true //过滤功能
					});

					C1 = window.location.href.split("?")[1];
					courierId = C1.split("=")[1];

					alert(C1);
					alert(courierId)
						/*$.ajax({
							url: 'randomdelivery/AdminController/courier/' + courierId,
							type: 'GET',
							async: true,
							dataType: "json",
							contentType: "application/json",
							data: {},
							success: function(data) {

							},
							error: function() {
								alert("服务器出错");
							}

						})*/
					expressdetail(courierId)
					EO_SelectChange(1)
				})

				function expressdetail(courierId) {
					/*$.ajax({
							url: 'randomdelivery/AdminController/courier/'+courierId,
							type: 'GET',
							dataType: 'json',
							contentType: "application/json",
							async: true,
							data: {},
							success: function(data) {*/
					$("#ehead").attr('src', data.courier.headPortraitUrl);
					$("#enickname").text(data.courier.nickname)
					$("#esex").text(data.courier.sex)
					$("#courierId").text(data.courier.courierId)
					$("#sumOrder").text(data.courier.sumOrder)
					$("#dayOrder").text(data.courier.dayOrder)
					$("#escore").text(data.courier.score)
					$("#ecreateTime").text(data.courier.createTime)
					/*}
							Error: function() {
								alert("服务器出错");
							}
					})*/
				}

				$(document).on('click', '.orderclose', function() {
					k = $(this).parents("tr").index() + 1;
					var element = this
					layui.use('layer', function() {
						var layer = layui.layer;
						layer.confirm('是否要关闭选中订单', {
							icon: 2,
							title: '提示'
						}, function(index) {
							layer.confirm('关闭订单后不可恢复 是否仍关闭订单？', {
								icon: 2,
								title: '提示'
							}, function(index) {
								/* $.ajax({
                             type: "get",
                             url: "/randomdelivery/AdminController/closeOrderByOrderId/"+element.id,
                             data: {},
                             async: true,
                             dataType: "json",
                             contentType: "application/json",
                             success: function(data) {*/
								if (data.code == 200) {
									$("table#expressdetailTable").find("tr:eq(" + k + ")").children('td:nth-child(5)').text("关闭").css('color', 'red');
									$("table#expressdetailTable").find("tr:eq(" + k + ")").children('td:nth-child(6)').children('.orderclose').attr('class', 'layui-btn layui-btn-disabled  layui-btn-small')
									layer.close(index);
								}
								/*},
                             Error: function() {
                                 alert("服务器出错");
                             }
                         })*/
							})
						});

					});
				})

				

				function EO_SelectChange(v) {
					/* $.ajax({
                     type: "get",
                     url: "/randomdelivery/AdminController/userPurchaseOrders/pageCount/1/pageSize/10",
                     data: {
                        "sequence": v,
						"userId": courierId
                     },
                     async: true,
                     dataType: "json",
                     contentType: "application/json",
                     success: function(data) {*/

					eodata(data2);
					/*},
                     Error: function() {
                         alert("服务器出错");
                     }
                 })*/
				}


				$("#expressDetailselect").bind("change", function() {
					EO_SelectChange($(this).val())

				})

				function expressOrder_Detail(orderId) {
					window.location.href = "../orderManage/orderdetail.html?orderId=" + orderId
				}

				Date.prototype.Format = function(fmt) { //author: meizz 
				var o = {
					"M+": this.getMonth() + 1, //月份 
					"d+": this.getDate(), //日 
					"h+": this.getHours(), //小时 
					"m+": this.getMinutes(), //分 
					"s+": this.getSeconds(), //秒 
					"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
					"S": this.getMilliseconds() //毫秒 
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
					if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			}

				function eodata(data) {
					$('#expressdetailTable').dataTable().fnClearTable(); //清除表格内
					$.each(data.orderStatisticalVos, function(index, item) {

						var orderState
						if (item.orderState == 0) {
							orderState = "等待代购人确定金额"
						} else if (item.orderState == 1) {
							orderState = "确认且未支付"
						} else if (item.orderState == 2) {
							orderState = "已支付"
						} else if (item.orderState == 3) {
							orderState = "找快递员"
						} else if (item.orderState == 4) {
							orderState = "待取件"
						} else if (item.orderState == 5) {
							orderState = "派送中"
						} else if (item.orderState == 6) {
							orderState = "完成"
						} else if (item.orderState == 7) {
							orderState = "关闭"
						} else if (item.orderState == 8) {
							orderState = "退款中"
						}

						var demandCreatetime = new Date(item.demandCreatetime).Format("yyyy-MM-dd hh:mm:ss")
						var arriveTime = new Date(item.arriveTime).Format("yyyy-MM-dd hh:mm:ss")
						$('#expressdetailTable').dataTable().fnAddData([
							demandCreatetime,
							arriveTime,
							'<img src=' + item.purchaseUserheadPortraitUrl + '><span>' + item.purchaseUserNickname + '</span>',
							'<img src=' + item.headPortraitUrl + '><span>' + item.nickname + '</span>',
							orderState,

							'<div class="layui-btn  layui-btn-small user_detail" onclick = "expressOrder_Detail(' + item.orderId + ')">详情</div><div class="layui-btn layui-btn-danger  layui-btn-small orderclose" id=' + item.orderId + '>关闭</div>'
						]);
						if (item.orderState == 7) {
							$("table#expressdetailTable").find("tr:eq(" + (index + 1) + ")").children('td:nth-child(6)').children('.orderclose').attr('class', 'layui-btn layui-btn-disabled  layui-btn-small')
							$("table#expressdetailTable").find("tr:eq(" + (index + 1) + ")").children('td:nth-child(5)').text("关闭").css('color', 'red');
						};
					})
				}

				
				</script>
				
			</div>
		</div>
	</body>
</html>